class Commodity {
    /**
     * 修改商品上下架状态
     * @param commodityId 商品id
     * @param status 商品状态
     * @returns {Promise<boolean>}
     */
    updateAllSelectedStatus(commodityId, status) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/status",
                method: "POST",
                data: {
                    commodityId: commodityId,
                    status: status
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }

    /**
     * 查看商品
     * @param commodityId 商品id
     * @returns {Promise<json>}
     */
    getCommodityById(commodityId) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/commodity/by/id",
                method: "GET",
                data: {
                    commodityId: commodityId,
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 上传图片图片
     * @param commodityImage 商品图片
     * @returns {Promise<boolean>} true新增成功 false新增失败
     */
    addCommodityImage(commodityImage) {
        // 创建一个 FormData 对象
        let formData = new FormData();
        formData.append('commodityImage', commodityImage);
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/add/commodity/image",
                method: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }
    /**
     * 上传视频
     * @param commodityVideo 商品视频
     * @returns {Promise<boolean>} true新增成功 false新增失败
     */
    addCommodityVideo(commodityVideo) {
        // 创建一个 FormData 对象
        let formData = new FormData();
        formData.append('commodityVideo', commodityVideo);
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/add/commodity/video",
                method: "POST",
                data: formData,
                processData: false,
                contentType: false,
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }
    /**
     * 删除视频
     * @param savePath 商品视频名称
     * @return {Promise<boolean>} true删除成功 false删除失败
     */
    deleteVideo(savePath) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/delete/commodity/video",
                method: "POST",
                data: {
                    videoName: savePath
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }
    /**
     * 删除图片
     * @param savePath 商品图片路径
     * @return {Promise<boolean>} true删除成功 false删除失败
     */
    deleteCommodityImage(savePath) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/delete/commodity/image",
                method: "POST",
                data: {
                    imagName: savePath
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 修改商品图片
     * @param newCommodityImageName 新商品图片
     * @param commodityId 商品Id
     * @returns {Promise<boolean>}
     */
    updateCommodityImage(newCommodityImageName, commodityId) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/image/name",
                method: "POST",
                data: {
                    newCommodityImageName: newCommodityImageName,
                    commodityId: commodityId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 根据商品Id修改键字
     * @param newCommodityKeyword 商品关键字
     * @param commodityId 商品Id
     * @return {Promise<boolean>} 修改成功返回true，失败返回false
     */
    updatedKeywordsById(newCommodityKeyword, commodityId) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/keywords",
                method: "POST",
                data: {
                    newCommodityKeyword: newCommodityKeyword,
                    commodityId: commodityId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 根据商品Id修改商品描述
     * @param commodityId 商品Id
     * @param commodityDescription 商品描述
     * @return {Promise<boolean>} 修改成功返回true，失败返回false
     * @throws SqlErrorException SQL执行异常
     */
    updateCommodityDescriptionById(commodityId, commodityDescription) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/description",
                method: "POST",
                data: {
                    description: commodityDescription,
                    commodityId: commodityId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 修改商品赠品
     * @param commodityGiftsId 赠品Id
     * @param giftsNumber 赠品库存
     * @return {Promise<boolean>}
     */
    updateGiftsNumberById(commodityGiftsId, giftsNumber) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/gifts/inventory",
                method: "POST",
                data: {
                    commodityGiftsId: commodityGiftsId,
                    giftsNumber: giftsNumber
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 查询商品赠品
     * @return {Promise<json>} 返回JSON
     */
    queryCommodityGiftsAndCommodity() {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/get/commofity/gifts",
                method: "GET",
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 根据商品Id修改商品赠品
     * @param commodityId 商品Id
     * @param commodityGiftsId 赠品Id
     * @return {Promise<boolean>} true修改成功 false修改失败
     */
    updateCommodityGiftsById(commodityId, commodityGiftsId) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commmodity/gitfts/id",
                method: "POST",
                data: {
                    commodityId: commodityId,
                    commodityGiftsId: commodityGiftsId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 根据商品ID修改商品折扣
     *
     * @param commodityId      商品ID
     * @param commodityDiscount 新的商品折扣
     * @return {Promise<boolean>} true修改成功 false修改失败
     */
    updateCommodityDiscountById(commodityId, commodityDiscount) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/discount/by/id",
                method: "POST",
                data: {
                    commodityId: commodityId,
                    commodityDiscount: commodityDiscount
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 根据商品ID修改商品价格
     *
     * @param commodityId      商品ID
     * @param newPrice 新的商品价格
     * @return {Promise<boolean>} true修改成功 false修改失败
     */
    updateCommodityPriceById(commodityId, newPrice) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/price/by/id",
                method: "POST",
                data: {
                    commodityId: commodityId,
                    newPrice: newPrice
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        })
    }

    /**
     * 修改商品名称
     * @param commodityId 商品Id
     * @param name 商品名称
     * @return {Promise<boolean>} true修改成功 false修改失败
     */
    updateCommodityNameById(commodityId, name) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/name",
                method: "POST",
                data: {
                    commodityId: commodityId,
                    name: name
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 新增商品保险
     * @param commodityInsurance 商品保险Json
     * @return {Promise<boolean>} true成功 false失败
     */
    addCommodityInsurance(commodityInsurance) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/add/commodity/insurance",
                method: "POST",
                data: {
                    commodityInsurance: JSON.stringify(commodityInsurance),
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 新增商品保险
     * @param commodityId 商品Id
     * @param insuranceId 保险Id
     * @return {Promise<boolean>} true成功 false失败
     */
    deleteCommodityInsuranceByCommodityIdAndInsuranceId(commodityId,insuranceId) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/delete/commodity/insurance",
                method: "GET",
                data: {
                    commodityId: commodityId,
                    insuranceId:insuranceId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 新增商品详细图片
     * @param commodityId 商品Id
     * @param detailsImages 商品详细图片
     * @return {Promise<boolean>} true成功 false失败
     */
    updateDetailsImagesByCommodityId(commodityId,detailsImages) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/details/image",
                method: "POST",
                data: {
                    commodityId: commodityId,
                    detailsImages:detailsImages
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 修改或新增商品图片
     * @param commodityId 商品Id
     * @param detailsVideo 商品详细图片
     * @return {Promise<boolean>} true成功 false失败
     */
    updateDetailsVideoByCommodityId(commodityId,detailsVideo) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/details/video",
                method: "POST",
                data: {
                    commodityId: commodityId,
                    detailsVideo:detailsVideo
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }

    /**
     * 修改或新增商品图片
     * @param commodityParameter 商品参数
     * @return {Promise<boolean>} true成功 false失败
     */
    addCommodityParameter(commodityParameter) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/add/commodity/parameter",
                method: "POST",
                data: {
                    commodityParameter: commodityParameter
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 删除商品参数
     * @param parameterId 商品参数Id
     * @return {Promise<boolean>} true成功 false失败
     */
    deleteCommodityParameterById(parameterId) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/delete/commodity/parameter/by/id",
                method: "GET",
                data: {
                    parameterId: parameterId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 修改商品服务
     * @param commodityServe 商品参数Id
     * @return {Promise<boolean>} true成功 false失败
     */
    updateByCommodityServe(commodityServe) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/update/commodity/serve",
                method: "POST",
                data: {
                    commodityServe: JSON.stringify(commodityServe)
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 根据类别查询
     * @param modelId 商品ModelId
     * @return {Promise<json>} true成功 false失败
     */
    findCategoryByModelId(modelId) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/get/find/category/by/model/id",
                method: "GET",
                data: {
                    modelId: modelId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 根据类别查询
     * @param categoryId 商品categoryId
     * @return {Promise<json>} true成功 false失败
     */
    findClassByCategoryId(categoryId) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/get/find/class/by/category/id",
                method: "GET",
                data: {
                    categoryId: categoryId
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
    /**
     * 根据类别查询
     * @param commodityJson 商品JSon
     * @param commoditySpecificationJson 商品规格
     * @return {Promise<json>} true成功 false失败
     */
    addCommodity(commodityJson,commoditySpecificationJson) {
        return new Promise((resolve, reject) => {
            $.ajax({
                url: "/www.xiaomi.com/background/add/commodity",
                method: "POST",
                data: {
                    commodityJson: JSON.stringify(commodityJson),
                    commoditySpecificationJson:JSON.stringify(commoditySpecificationJson)
                },
                success: function (response) {
                    resolve(response);
                },
                error: function (error) {
                    reject(error);
                }
            });
        });
    }
}